<?php

/**
 * Profile form base class.
 *
 * @method Profile getObject() Returns the current form's model object
 *
 * @package    Onnobostro
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id$
 */
abstract class BaseProfileForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                 => new sfWidgetFormInputHidden(),
      'user_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => false)),
      'title'              => new sfWidgetFormChoice(array('choices' => array('Mr' => 'Mr', 'Mss' => 'Mss'))),
      'first_name'         => new sfWidgetFormInputText(),
      'last_name'          => new sfWidgetFormInputText(),
      'nick_name'          => new sfWidgetFormInputText(),
      'company'            => new sfWidgetFormInputText(),
      'phone_no'           => new sfWidgetFormInputText(),
      'phone_no1'          => new sfWidgetFormInputText(),
      'land_phone_no'      => new sfWidgetFormInputText(),
      'fax'                => new sfWidgetFormInputText(),
      'street_address1'    => new sfWidgetFormInputText(),
      'street_address2'    => new sfWidgetFormInputText(),
      'city'               => new sfWidgetFormInputText(),
      'post_code'          => new sfWidgetFormInputText(),
      'state'              => new sfWidgetFormInputText(),
      'country'            => new sfWidgetFormInputText(),
      'message'            => new sfWidgetFormInputText(),
      'shipping_address1'  => new sfWidgetFormInputText(),
      'shipping_address2'  => new sfWidgetFormInputText(),
      'shipping_city'      => new sfWidgetFormInputText(),
      'shipping_post_code' => new sfWidgetFormInputText(),
      'shipping_country'   => new sfWidgetFormInputText(),
      'contact_person'     => new sfWidgetFormInputText(),
      'contact_phone'      => new sfWidgetFormInputText(),
      'delivery_time'      => new sfWidgetFormInputText(),
      'terms'              => new sfWidgetFormInputCheckbox(),

    ));

    $this->setValidators(array(
      'id'                 => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'user_id'            => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'))),
      'title'              => new sfValidatorChoice(array('choices' => array(0 => 'Mr', 1 => 'Mss'), 'required' => false)),
      'first_name'         => new sfValidatorString(array('max_length' => 50)),
      'last_name'          => new sfValidatorString(array('max_length' => 50)),
      'nick_name'          => new sfValidatorString(array('max_length' => 50)),
      'company'            => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'phone_no'           => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'phone_no1'          => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'land_phone_no'      => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'fax'                => new sfValidatorString(array('max_length' => 20, 'required' => false)),
      'street_address1'    => new sfValidatorString(array('max_length' => 255)),
      'street_address2'    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'city'               => new sfValidatorString(array('max_length' => 100)),
      'post_code'          => new sfValidatorString(array('max_length' => 50)),
      'state'              => new sfValidatorString(array('max_length' => 100, 'required' => false)),
      'country'            => new sfValidatorString(array('max_length' => 100)),
      'message'            => new sfValidatorString(array('max_length' => 150, 'required' => false)),
      'shipping_address1'  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'shipping_address2'  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'shipping_city'      => new sfValidatorString(array('max_length' => 100, 'required' => false)),
      'shipping_post_code' => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'shipping_country'   => new sfValidatorString(array('max_length' => 100, 'required' => false)),
      'contact_person'     => new sfValidatorString(array('max_length' => 100, 'required' => false)),
      'contact_phone'      => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'delivery_time'      => new sfValidatorString(array('max_length' => 200, 'required' => false)),
      'terms'              => new sfValidatorBoolean(),
    ));

    $this->widgetSchema->setNameFormat('profile[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
    
    // Unset automatic fields like 'created_at', 'updated_at', 'position'
    // override this method in your form to keep them
    parent::unsetAutoFields();
  }


  protected function doBind(array $values)
  {
    parent::doBind($values);
  }
  
  public function processValues($values)
  {
    $values = parent::processValues($values);
    return $values;
  }
  
  protected function doUpdateObject($values)
  {
    parent::doUpdateObject($values);
  }

  public function getModelName()
  {
    return 'Profile';
  }

}